package fr.inserm.um915.bdibd.model;

import java.util.ArrayList;
import java.util.List;

import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

public class Marker implements Comparable<Marker>
	{
	int index;
	 String name;
	 ChromPosition position;
	 List<Float> genMap=new ArrayList<Float>(3);
	
	public static final TupleBinding<Marker> BINDING=new TupleBinding<Marker>()
		{
		private ChromPosition.Binding posBing=new ChromPosition.Binding();
		@Override
		public void objectToEntry(Marker o, TupleOutput out)
			{
			out.writeInt(o.index);
			out.writeString(o.name);	
			out.writeByte(o.genMap.size());
			for(Float f:o.genMap)
				{
				out.writeFloat(f);
				}
			posBing.objectToEntry(o.position, out);
			}
			
		@Override
		public Marker entryToObject(TupleInput in) {
			Marker m=new Marker();
			m.index=in.readInt();
			m.name=in.readString();
			int n=in.readByte();
			for(int i=0;i< n;++i)
				{
				m.genMap.add(in.readFloat());
				}
			m.position=this.posBing.entryToObject(in);
			return m;
			}
		};
	
	
	public String getName()
		{
		return name;
		}
	
	public ChromPosition getPosition()
		{
		return position;
		}
	
	public List<Float> getGenMap()
		{
		return genMap;
		}
	public String getGenMapAsString()
		{
		StringBuilder b=new StringBuilder();
		for(int i=0;i< genMap.size();++i)
			{
			if(i>0) b.append('|');
			b.append(genMap.get(i));
			}
		return b.toString();
		}
	@Override
	public int compareTo(Marker o) {
		int i= position.compareTo(o.position);
		if(i!=0) return i;
		i= name.compareToIgnoreCase(o.name);
		if(i!=0) return i;
		return 0;
		}
	@Override
	public String toString()
		{
		return "("+index+") "+name+" "+position+" "+getGenMapAsString();
		}
	
	}
